package edu.gmu.projects.fireresponder.environment;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class Building extends Asset {

	public static final int TIME_TO_COMPLETE = 300;
	private Location centerPoint;
	private Set<Location> entryPoints;
	private Set<Location> allPoints;
	private Set<Location> perimeterPoints;
	private boolean cleared;
	private Set<Asset> connectedAssets;
	
	public Building() {
		entryPoints = new HashSet<Location>();
		allPoints = new HashSet<Location>();
		connectedAssets = new HashSet<Asset>();
	}

	public Building(String id) {
		this();
		this.setId(id);
	}

	public boolean isCleared() {
		return cleared;
	}

	public void setCleared(boolean cleared) {
		this.cleared = cleared;
	}

	public Location getCenterPoint() {
		return centerPoint;
	}
	
	public void setCenterPoint(Location centerPoint) {
		this.centerPoint = centerPoint;
		allPoints.add(centerPoint);
	}

	public Set<Location> getEntryPoints() {
		return entryPoints;
	}

	public void setEntryPoints(Set<Location> entryPoints) {
		this.entryPoints = entryPoints;
		allPoints.addAll(entryPoints);
	}

	public void addEntryPoints(Location entryPoint) {
		this.entryPoints.add(entryPoint);
		allPoints.add(entryPoint);
	}
	
	public void addEntryPoints(Set<Location> entryPoints) {
		this.entryPoints.addAll(entryPoints);
		allPoints.addAll(entryPoints);
	}

	public Set<Location> getPerimeterPoints() {
		return perimeterPoints;
	}

	public void setPerimeterPoints(Set<Location> perimeterPoints) {
		this.perimeterPoints = perimeterPoints;
		allPoints.addAll(perimeterPoints);
	}

	public void addPerimeterPoints(Location perimeterPoint) {
		this.perimeterPoints.add(perimeterPoint);
		allPoints.add(perimeterPoint);
	}
	
	public void addPerimeterPoints(Set<Location> perimeterPoints) {
		this.perimeterPoints.addAll(perimeterPoints);
		allPoints.addAll(perimeterPoints);
	}

	public boolean isConnectedToPath(Path path) {
		return path.isConnectedToBuilding(this);
	}

	public int getEstimatedTimeToComplete() {
		return TIME_TO_COMPLETE;
	}

	public Set<Location> getPoints() {
		return allPoints;
	}

	public int compareTo(Asset o) {
		Building b = (Building)o;
		return this.centerPoint.compareTo(b.getCenterPoint());
	}

	public Location getCenter() {
		return centerPoint;
	}

	public void addConnectedAsset(Asset asset) {
		connectedAssets.add(asset);
	}

	public Collection<Asset> getConnectedAssets() {
		return connectedAssets;
	}
	
	public String toString() {
		return "Building: " + getId();
	}

}